# 作者: spy
# 开发时间: 2021/12/14 8:54
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from base.base_page import BasePage


class LoginPage(BasePage):
    """登录页面"""

    # 页面的元素
    username_loc = (By.ID, "username")  # 用户名
    password_loc = (By.ID, "password")  # 密码
    submit_loc = (By.XPATH, "//form/button")  # 登录按钮
    welcome_loc = (By.XPATH, "//span[text()='欢迎']")

    # 页面的动作
    def login_TTOS(self, username, password):
        # 等待元素加载完成
        WebDriverWait(self.driver, 30).until(
            EC.visibility_of_element_located((By.ID, "username")))

        self.set_keys(LoginPage.username_loc, username)  # 输入用户名
        self.set_keys(LoginPage.password_loc, password)  # 输入密码
        self.click(LoginPage.submit_loc)  # 点击登录按钮

    # 断言
    def get_except_result(self):
        return self.get_value(LoginPage.welcome_loc)
